<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
</head>
<body>
<main role="main">
<div class="sourceContainer">
<pre><span class="sourceLineNo">001</span><a id="line.1">/*</a>
<span class="sourceLineNo">002</span><a id="line.2"> * Licensed to the Apache Software Foundation (ASF) under one or more</a>
<span class="sourceLineNo">003</span><a id="line.3"> * contributor license agreements.  See the NOTICE file distributed with</a>
<span class="sourceLineNo">004</span><a id="line.4"> * this work for additional information regarding copyright ownership.</a>
<span class="sourceLineNo">005</span><a id="line.5"> * The ASF licenses this file to You under the Apache License, Version 2.0</a>
<span class="sourceLineNo">006</span><a id="line.6"> * (the "License"); you may not use this file except in compliance with</a>
<span class="sourceLineNo">007</span><a id="line.7"> * the License.  You may obtain a copy of the License at</a>
<span class="sourceLineNo">008</span><a id="line.8"> *</a>
<span class="sourceLineNo">009</span><a id="line.9"> *      http://www.apache.org/licenses/LICENSE-2.0</a>
<span class="sourceLineNo">010</span><a id="line.10"> *</a>
<span class="sourceLineNo">011</span><a id="line.11"> * Unless required by applicable law or agreed to in writing, software</a>
<span class="sourceLineNo">012</span><a id="line.12"> * distributed under the License is distributed on an "AS IS" BASIS,</a>
<span class="sourceLineNo">013</span><a id="line.13"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</a>
<span class="sourceLineNo">014</span><a id="line.14"> * See the License for the specific language governing permissions and</a>
<span class="sourceLineNo">015</span><a id="line.15"> * limitations under the License.</a>
<span class="sourceLineNo">016</span><a id="line.16"> */</a>
<span class="sourceLineNo">017</span><a id="line.17">package org.apache.commons.dbutils;</a>
<span class="sourceLineNo">018</span><a id="line.18"></a>
<span class="sourceLineNo">019</span><a id="line.19">import java.sql.Connection;</a>
<span class="sourceLineNo">020</span><a id="line.20">import java.sql.PreparedStatement;</a>
<span class="sourceLineNo">021</span><a id="line.21">import java.sql.ResultSet;</a>
<span class="sourceLineNo">022</span><a id="line.22">import java.sql.SQLException;</a>
<span class="sourceLineNo">023</span><a id="line.23">import java.util.concurrent.Callable;</a>
<span class="sourceLineNo">024</span><a id="line.24">import java.util.concurrent.ExecutorService;</a>
<span class="sourceLineNo">025</span><a id="line.25">import java.util.concurrent.Future;</a>
<span class="sourceLineNo">026</span><a id="line.26"></a>
<span class="sourceLineNo">027</span><a id="line.27">import javax.sql.DataSource;</a>
<span class="sourceLineNo">028</span><a id="line.28"></a>
<span class="sourceLineNo">029</span><a id="line.29">/**</a>
<span class="sourceLineNo">030</span><a id="line.30"> * Executes SQL queries with pluggable strategies for handling</a>
<span class="sourceLineNo">031</span><a id="line.31"> * {@code ResultSet}s.  This class is thread safe.</a>
<span class="sourceLineNo">032</span><a id="line.32"> *</a>
<span class="sourceLineNo">033</span><a id="line.33"> * @see ResultSetHandler</a>
<span class="sourceLineNo">034</span><a id="line.34"> * @since 1.4</a>
<span class="sourceLineNo">035</span><a id="line.35"> */</a>
<span class="sourceLineNo">036</span><a id="line.36">public class AsyncQueryRunner extends AbstractQueryRunner {</a>
<span class="sourceLineNo">037</span><a id="line.37"></a>
<span class="sourceLineNo">038</span><a id="line.38">    private final ExecutorService executorService;</a>
<span class="sourceLineNo">039</span><a id="line.39">    private final QueryRunner queryRunner;</a>
<span class="sourceLineNo">040</span><a id="line.40"></a>
<span class="sourceLineNo">041</span><a id="line.41">    /**</a>
<span class="sourceLineNo">042</span><a id="line.42">     * Constructor for AsyncQueryRunner which uses a provided ExecutorService and underlying QueryRunner.</a>
<span class="sourceLineNo">043</span><a id="line.43">     *</a>
<span class="sourceLineNo">044</span><a id="line.44">     * @param executorService the {@code ExecutorService} instance used to run JDBC invocations concurrently.</a>
<span class="sourceLineNo">045</span><a id="line.45">     * @param queryRunner the {@code QueryRunner} instance to use for the queries.</a>
<span class="sourceLineNo">046</span><a id="line.46">     * @since DbUtils 1.5</a>
<span class="sourceLineNo">047</span><a id="line.47">     */</a>
<span class="sourceLineNo">048</span><a id="line.48">    public AsyncQueryRunner(final ExecutorService executorService, final QueryRunner queryRunner) {</a>
<span class="sourceLineNo">049</span><a id="line.49">        this.executorService = executorService;</a>
<span class="sourceLineNo">050</span><a id="line.50">        this.queryRunner = queryRunner;</a>
<span class="sourceLineNo">051</span><a id="line.51">    }</a>
<span class="sourceLineNo">052</span><a id="line.52"></a>
<span class="sourceLineNo">053</span><a id="line.53">    /**</a>
<span class="sourceLineNo">054</span><a id="line.54">     * Constructor for AsyncQueryRunner.</a>
<span class="sourceLineNo">055</span><a id="line.55">     *</a>
<span class="sourceLineNo">056</span><a id="line.56">     * @param executorService the {@code ExecutorService} instance used to run JDBC invocations concurrently.</a>
<span class="sourceLineNo">057</span><a id="line.57">     */</a>
<span class="sourceLineNo">058</span><a id="line.58">    public AsyncQueryRunner(final ExecutorService executorService) {</a>
<span class="sourceLineNo">059</span><a id="line.59">        this(null, false, executorService);</a>
<span class="sourceLineNo">060</span><a id="line.60">    }</a>
<span class="sourceLineNo">061</span><a id="line.61"></a>
<span class="sourceLineNo">062</span><a id="line.62">    /**</a>
<span class="sourceLineNo">063</span><a id="line.63">     * @deprecated Use {@link #AsyncQueryRunner(ExecutorService, QueryRunner)} instead.</a>
<span class="sourceLineNo">064</span><a id="line.64">     * Constructor for AsyncQueryRunner that controls the use of {@code ParameterMetaData}.</a>
<span class="sourceLineNo">065</span><a id="line.65">     *</a>
<span class="sourceLineNo">066</span><a id="line.66">     * @param pmdKnownBroken Some drivers don't support {@link java.sql.ParameterMetaData#getParameterType(int) };</a>
<span class="sourceLineNo">067</span><a id="line.67">     * if {@code pmdKnownBroken} is set to true, we won't even try it; if false, we'll try it,</a>
<span class="sourceLineNo">068</span><a id="line.68">     * and if it breaks, we'll remember not to use it again.</a>
<span class="sourceLineNo">069</span><a id="line.69">     * @param executorService the {@code ExecutorService} instance used to run JDBC invocations concurrently.</a>
<span class="sourceLineNo">070</span><a id="line.70">     */</a>
<span class="sourceLineNo">071</span><a id="line.71">    @Deprecated</a>
<span class="sourceLineNo">072</span><a id="line.72">    public AsyncQueryRunner(final boolean pmdKnownBroken, final ExecutorService executorService) {</a>
<span class="sourceLineNo">073</span><a id="line.73">        this(null, pmdKnownBroken, executorService);</a>
<span class="sourceLineNo">074</span><a id="line.74">    }</a>
<span class="sourceLineNo">075</span><a id="line.75"></a>
<span class="sourceLineNo">076</span><a id="line.76">    /**</a>
<span class="sourceLineNo">077</span><a id="line.77">     * @deprecated Use {@link #AsyncQueryRunner(ExecutorService, QueryRunner)} instead.</a>
<span class="sourceLineNo">078</span><a id="line.78">     * Constructor for AsyncQueryRunner that takes a {@code DataSource}.</a>
<span class="sourceLineNo">079</span><a id="line.79">     *</a>
<span class="sourceLineNo">080</span><a id="line.80">     * Methods that do not take a {@code Connection} parameter will retrieve connections from this</a>
<span class="sourceLineNo">081</span><a id="line.81">     * {@code DataSource}.</a>
<span class="sourceLineNo">082</span><a id="line.82">     *</a>
<span class="sourceLineNo">083</span><a id="line.83">     * @param ds The {@code DataSource} to retrieve connections from.</a>
<span class="sourceLineNo">084</span><a id="line.84">     * @param executorService the {@code ExecutorService} instance used to run JDBC invocations concurrently.</a>
<span class="sourceLineNo">085</span><a id="line.85">     */</a>
<span class="sourceLineNo">086</span><a id="line.86">    @Deprecated</a>
<span class="sourceLineNo">087</span><a id="line.87">    public AsyncQueryRunner(final DataSource ds, final ExecutorService executorService) {</a>
<span class="sourceLineNo">088</span><a id="line.88">        this(ds, false, executorService);</a>
<span class="sourceLineNo">089</span><a id="line.89">    }</a>
<span class="sourceLineNo">090</span><a id="line.90"></a>
<span class="sourceLineNo">091</span><a id="line.91">    /**</a>
<span class="sourceLineNo">092</span><a id="line.92">     * @deprecated Use {@link #AsyncQueryRunner(ExecutorService, QueryRunner)} instead.</a>
<span class="sourceLineNo">093</span><a id="line.93">     * Constructor for AsyncQueryRunner that take a {@code DataSource} and controls the use of {@code ParameterMetaData}.</a>
<span class="sourceLineNo">094</span><a id="line.94">     * Methods that do not take a {@code Connection} parameter will retrieve connections from this</a>
<span class="sourceLineNo">095</span><a id="line.95">     * {@code DataSource}.</a>
<span class="sourceLineNo">096</span><a id="line.96">     *</a>
<span class="sourceLineNo">097</span><a id="line.97">     * @param ds The {@code DataSource} to retrieve connections from.</a>
<span class="sourceLineNo">098</span><a id="line.98">     * @param pmdKnownBroken Some drivers don't support {@link java.sql.ParameterMetaData#getParameterType(int) };</a>
<span class="sourceLineNo">099</span><a id="line.99">     * if {@code pmdKnownBroken} is set to true, we won't even try it; if false, we'll try it,</a>
<span class="sourceLineNo">100</span><a id="line.100">     * and if it breaks, we'll remember not to use it again.</a>
<span class="sourceLineNo">101</span><a id="line.101">     * @param executorService the {@code ExecutorService} instance used to run JDBC invocations concurrently.</a>
<span class="sourceLineNo">102</span><a id="line.102">     */</a>
<span class="sourceLineNo">103</span><a id="line.103">    @Deprecated</a>
<span class="sourceLineNo">104</span><a id="line.104">    public AsyncQueryRunner(final DataSource ds, final boolean pmdKnownBroken, final ExecutorService executorService) {</a>
<span class="sourceLineNo">105</span><a id="line.105">        super(ds, pmdKnownBroken);</a>
<span class="sourceLineNo">106</span><a id="line.106">        this.executorService = executorService;</a>
<span class="sourceLineNo">107</span><a id="line.107">        this.queryRunner = new QueryRunner(ds, pmdKnownBroken);</a>
<span class="sourceLineNo">108</span><a id="line.108">    }</a>
<span class="sourceLineNo">109</span><a id="line.109"></a>
<span class="sourceLineNo">110</span><a id="line.110">    /**</a>
<span class="sourceLineNo">111</span><a id="line.111">     * @deprecated No longer used by this class. Will be removed in a future version.</a>
<span class="sourceLineNo">112</span><a id="line.112">     * Class that encapsulates the continuation for batch calls.</a>
<span class="sourceLineNo">113</span><a id="line.113">     */</a>
<span class="sourceLineNo">114</span><a id="line.114">    @Deprecated</a>
<span class="sourceLineNo">115</span><a id="line.115">    protected class BatchCallableStatement implements Callable&lt;int[]&gt; {</a>
<span class="sourceLineNo">116</span><a id="line.116">        private final String sql;</a>
<span class="sourceLineNo">117</span><a id="line.117">        private final Object[][] params;</a>
<span class="sourceLineNo">118</span><a id="line.118">        private final Connection conn;</a>
<span class="sourceLineNo">119</span><a id="line.119">        private final boolean closeConn;</a>
<span class="sourceLineNo">120</span><a id="line.120">        private final PreparedStatement ps;</a>
<span class="sourceLineNo">121</span><a id="line.121"></a>
<span class="sourceLineNo">122</span><a id="line.122">        /**</a>
<span class="sourceLineNo">123</span><a id="line.123">         * Creates a new BatchCallableStatement instance.</a>
<span class="sourceLineNo">124</span><a id="line.124">         *</a>
<span class="sourceLineNo">125</span><a id="line.125">         * @param sql The SQL statement to execute.</a>
<span class="sourceLineNo">126</span><a id="line.126">         * @param params An array of query replacement parameters.  Each row in</a>
<span class="sourceLineNo">127</span><a id="line.127">         *        this array is one set of batch replacement values.</a>
<span class="sourceLineNo">128</span><a id="line.128">         * @param conn The connection to use for the batch call.</a>
<span class="sourceLineNo">129</span><a id="line.129">         * @param closeConn True if the connection should be closed, false otherwise.</a>
<span class="sourceLineNo">130</span><a id="line.130">         * @param ps The {@link PreparedStatement} to be executed.</a>
<span class="sourceLineNo">131</span><a id="line.131">         */</a>
<span class="sourceLineNo">132</span><a id="line.132">        public BatchCallableStatement(final String sql, final Object[][] params, final Connection conn, final boolean closeConn, final PreparedStatement ps) {</a>
<span class="sourceLineNo">133</span><a id="line.133">            this.sql = sql;</a>
<span class="sourceLineNo">134</span><a id="line.134">            this.params = params.clone();</a>
<span class="sourceLineNo">135</span><a id="line.135">            this.conn = conn;</a>
<span class="sourceLineNo">136</span><a id="line.136">            this.closeConn = closeConn;</a>
<span class="sourceLineNo">137</span><a id="line.137">            this.ps = ps;</a>
<span class="sourceLineNo">138</span><a id="line.138">        }</a>
<span class="sourceLineNo">139</span><a id="line.139"></a>
<span class="sourceLineNo">140</span><a id="line.140">        /**</a>
<span class="sourceLineNo">141</span><a id="line.141">         * The actual call to executeBatch.</a>
<span class="sourceLineNo">142</span><a id="line.142">         *</a>
<span class="sourceLineNo">143</span><a id="line.143">         * @return an array of update counts containing one element for each command in the batch.</a>
<span class="sourceLineNo">144</span><a id="line.144">         * @throws SQLException if a database access error occurs or one of the commands sent to the database fails.</a>
<span class="sourceLineNo">145</span><a id="line.145">         * @see PreparedStatement#executeBatch()</a>
<span class="sourceLineNo">146</span><a id="line.146">         */</a>
<span class="sourceLineNo">147</span><a id="line.147">        @Override</a>
<span class="sourceLineNo">148</span><a id="line.148">        public int[] call() throws SQLException {</a>
<span class="sourceLineNo">149</span><a id="line.149">            int[] ret = null;</a>
<span class="sourceLineNo">150</span><a id="line.150"></a>
<span class="sourceLineNo">151</span><a id="line.151">            try {</a>
<span class="sourceLineNo">152</span><a id="line.152">                ret = ps.executeBatch();</a>
<span class="sourceLineNo">153</span><a id="line.153">            } catch (final SQLException e) {</a>
<span class="sourceLineNo">154</span><a id="line.154">                rethrow(e, sql, (Object[])params);</a>
<span class="sourceLineNo">155</span><a id="line.155">            } finally {</a>
<span class="sourceLineNo">156</span><a id="line.156">                close(ps);</a>
<span class="sourceLineNo">157</span><a id="line.157">                if (closeConn) {</a>
<span class="sourceLineNo">158</span><a id="line.158">                    close(conn);</a>
<span class="sourceLineNo">159</span><a id="line.159">                }</a>
<span class="sourceLineNo">160</span><a id="line.160">            }</a>
<span class="sourceLineNo">161</span><a id="line.161"></a>
<span class="sourceLineNo">162</span><a id="line.162">            return ret;</a>
<span class="sourceLineNo">163</span><a id="line.163">        }</a>
<span class="sourceLineNo">164</span><a id="line.164">    }</a>
<span class="sourceLineNo">165</span><a id="line.165"></a>
<span class="sourceLineNo">166</span><a id="line.166">    /**</a>
<span class="sourceLineNo">167</span><a id="line.167">     * Execute a batch of SQL INSERT, UPDATE, or DELETE queries.</a>
<span class="sourceLineNo">168</span><a id="line.168">     *</a>
<span class="sourceLineNo">169</span><a id="line.169">     * @param conn The {@code Connection} to use to run the query.  The caller is</a>
<span class="sourceLineNo">170</span><a id="line.170">     * responsible for closing this Connection.</a>
<span class="sourceLineNo">171</span><a id="line.171">     * @param sql The SQL to execute.</a>
<span class="sourceLineNo">172</span><a id="line.172">     * @param params An array of query replacement parameters.  Each row in</a>
<span class="sourceLineNo">173</span><a id="line.173">     * this array is one set of batch replacement values.</a>
<span class="sourceLineNo">174</span><a id="line.174">     * @return A {@code Future} which returns the number of rows updated per statement.</a>
<span class="sourceLineNo">175</span><a id="line.175">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">176</span><a id="line.176">     */</a>
<span class="sourceLineNo">177</span><a id="line.177">    public Future&lt;int[]&gt; batch(final Connection conn, final String sql, final Object[][] params) throws SQLException {</a>
<span class="sourceLineNo">178</span><a id="line.178">        return executorService.submit(new Callable&lt;int[]&gt;() {</a>
<span class="sourceLineNo">179</span><a id="line.179"></a>
<span class="sourceLineNo">180</span><a id="line.180">            @Override</a>
<span class="sourceLineNo">181</span><a id="line.181">            public int[] call() throws Exception {</a>
<span class="sourceLineNo">182</span><a id="line.182">                return queryRunner.batch(conn, sql, params);</a>
<span class="sourceLineNo">183</span><a id="line.183">            }</a>
<span class="sourceLineNo">184</span><a id="line.184"></a>
<span class="sourceLineNo">185</span><a id="line.185">        });</a>
<span class="sourceLineNo">186</span><a id="line.186">    }</a>
<span class="sourceLineNo">187</span><a id="line.187"></a>
<span class="sourceLineNo">188</span><a id="line.188">    /**</a>
<span class="sourceLineNo">189</span><a id="line.189">     * Execute a batch of SQL INSERT, UPDATE, or DELETE queries.  The</a>
<span class="sourceLineNo">190</span><a id="line.190">     * {@code Connection} is retrieved from the {@code DataSource}</a>
<span class="sourceLineNo">191</span><a id="line.191">     * set in the constructor.  This {@code Connection} must be in</a>
<span class="sourceLineNo">192</span><a id="line.192">     * auto-commit mode or the update will not be saved.</a>
<span class="sourceLineNo">193</span><a id="line.193">     *</a>
<span class="sourceLineNo">194</span><a id="line.194">     * @param sql The SQL to execute.</a>
<span class="sourceLineNo">195</span><a id="line.195">     * @param params An array of query replacement parameters.  Each row in</a>
<span class="sourceLineNo">196</span><a id="line.196">     * this array is one set of batch replacement values.</a>
<span class="sourceLineNo">197</span><a id="line.197">     * @return A {@code Future} which returns the number of rows updated per statement.</a>
<span class="sourceLineNo">198</span><a id="line.198">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">199</span><a id="line.199">     */</a>
<span class="sourceLineNo">200</span><a id="line.200">    public Future&lt;int[]&gt; batch(final String sql, final Object[][] params) throws SQLException {</a>
<span class="sourceLineNo">201</span><a id="line.201">        return executorService.submit(new Callable&lt;int[]&gt;() {</a>
<span class="sourceLineNo">202</span><a id="line.202"></a>
<span class="sourceLineNo">203</span><a id="line.203">            @Override</a>
<span class="sourceLineNo">204</span><a id="line.204">            public int[] call() throws Exception {</a>
<span class="sourceLineNo">205</span><a id="line.205">                return queryRunner.batch(sql, params);</a>
<span class="sourceLineNo">206</span><a id="line.206">            }</a>
<span class="sourceLineNo">207</span><a id="line.207"></a>
<span class="sourceLineNo">208</span><a id="line.208">        });</a>
<span class="sourceLineNo">209</span><a id="line.209">    }</a>
<span class="sourceLineNo">210</span><a id="line.210"></a>
<span class="sourceLineNo">211</span><a id="line.211">    /**</a>
<span class="sourceLineNo">212</span><a id="line.212">     * Class that encapsulates the continuation for query calls.</a>
<span class="sourceLineNo">213</span><a id="line.213">     * @param &lt;T&gt; The type of the result from the call to handle.</a>
<span class="sourceLineNo">214</span><a id="line.214">     */</a>
<span class="sourceLineNo">215</span><a id="line.215">    protected class QueryCallableStatement&lt;T&gt; implements Callable&lt;T&gt; {</a>
<span class="sourceLineNo">216</span><a id="line.216">        private final String sql;</a>
<span class="sourceLineNo">217</span><a id="line.217">        private final Object[] params;</a>
<span class="sourceLineNo">218</span><a id="line.218">        private final Connection conn;</a>
<span class="sourceLineNo">219</span><a id="line.219">        private final boolean closeConn;</a>
<span class="sourceLineNo">220</span><a id="line.220">        private final PreparedStatement ps;</a>
<span class="sourceLineNo">221</span><a id="line.221">        private final ResultSetHandler&lt;T&gt; rsh;</a>
<span class="sourceLineNo">222</span><a id="line.222"></a>
<span class="sourceLineNo">223</span><a id="line.223">        /**</a>
<span class="sourceLineNo">224</span><a id="line.224">         * Creates a new {@code QueryCallableStatement} instance.</a>
<span class="sourceLineNo">225</span><a id="line.225">         *</a>
<span class="sourceLineNo">226</span><a id="line.226">         * @param conn The connection to use for the batch call.</a>
<span class="sourceLineNo">227</span><a id="line.227">         * @param closeConn True if the connection should be closed, false otherwise.</a>
<span class="sourceLineNo">228</span><a id="line.228">         * @param ps The {@link PreparedStatement} to be executed.</a>
<span class="sourceLineNo">229</span><a id="line.229">         * @param rsh The handler that converts the results into an object.</a>
<span class="sourceLineNo">230</span><a id="line.230">         * @param sql The SQL statement to execute.</a>
<span class="sourceLineNo">231</span><a id="line.231">         * @param params An array of query replacement parameters.  Each row in</a>
<span class="sourceLineNo">232</span><a id="line.232">         *        this array is one set of batch replacement values.</a>
<span class="sourceLineNo">233</span><a id="line.233">         */</a>
<span class="sourceLineNo">234</span><a id="line.234">        public QueryCallableStatement(final Connection conn, final boolean closeConn, final PreparedStatement ps,</a>
<span class="sourceLineNo">235</span><a id="line.235">                final ResultSetHandler&lt;T&gt; rsh, final String sql, final Object... params) {</a>
<span class="sourceLineNo">236</span><a id="line.236">            this.sql = sql;</a>
<span class="sourceLineNo">237</span><a id="line.237">            this.params = params;</a>
<span class="sourceLineNo">238</span><a id="line.238">            this.conn = conn;</a>
<span class="sourceLineNo">239</span><a id="line.239">            this.closeConn = closeConn;</a>
<span class="sourceLineNo">240</span><a id="line.240">            this.ps = ps;</a>
<span class="sourceLineNo">241</span><a id="line.241">            this.rsh = rsh;</a>
<span class="sourceLineNo">242</span><a id="line.242">        }</a>
<span class="sourceLineNo">243</span><a id="line.243"></a>
<span class="sourceLineNo">244</span><a id="line.244">        /**</a>
<span class="sourceLineNo">245</span><a id="line.245">         * The actual call to {@code handle()} method.</a>
<span class="sourceLineNo">246</span><a id="line.246">         *</a>
<span class="sourceLineNo">247</span><a id="line.247">         * @return an array of update counts containing one element for each command in the batch.</a>
<span class="sourceLineNo">248</span><a id="line.248">         * @throws SQLException if a database access error occurs.</a>
<span class="sourceLineNo">249</span><a id="line.249">         * @see ResultSetHandler#handle(ResultSet)</a>
<span class="sourceLineNo">250</span><a id="line.250">         */</a>
<span class="sourceLineNo">251</span><a id="line.251">        @Override</a>
<span class="sourceLineNo">252</span><a id="line.252">        public T call() throws SQLException {</a>
<span class="sourceLineNo">253</span><a id="line.253">            ResultSet rs = null;</a>
<span class="sourceLineNo">254</span><a id="line.254">            T ret = null;</a>
<span class="sourceLineNo">255</span><a id="line.255"></a>
<span class="sourceLineNo">256</span><a id="line.256">            try {</a>
<span class="sourceLineNo">257</span><a id="line.257">                rs = wrap(ps.executeQuery());</a>
<span class="sourceLineNo">258</span><a id="line.258">                ret = rsh.handle(rs);</a>
<span class="sourceLineNo">259</span><a id="line.259">            } catch (final SQLException e) {</a>
<span class="sourceLineNo">260</span><a id="line.260">                rethrow(e, sql, params);</a>
<span class="sourceLineNo">261</span><a id="line.261">            } finally {</a>
<span class="sourceLineNo">262</span><a id="line.262">                try {</a>
<span class="sourceLineNo">263</span><a id="line.263">                    close(rs);</a>
<span class="sourceLineNo">264</span><a id="line.264">                } finally {</a>
<span class="sourceLineNo">265</span><a id="line.265">                    close(ps);</a>
<span class="sourceLineNo">266</span><a id="line.266">                    if (closeConn) {</a>
<span class="sourceLineNo">267</span><a id="line.267">                        close(conn);</a>
<span class="sourceLineNo">268</span><a id="line.268">                    }</a>
<span class="sourceLineNo">269</span><a id="line.269">                }</a>
<span class="sourceLineNo">270</span><a id="line.270">            }</a>
<span class="sourceLineNo">271</span><a id="line.271"></a>
<span class="sourceLineNo">272</span><a id="line.272">            return ret;</a>
<span class="sourceLineNo">273</span><a id="line.273">        }</a>
<span class="sourceLineNo">274</span><a id="line.274"></a>
<span class="sourceLineNo">275</span><a id="line.275">    }</a>
<span class="sourceLineNo">276</span><a id="line.276"></a>
<span class="sourceLineNo">277</span><a id="line.277">    /**</a>
<span class="sourceLineNo">278</span><a id="line.278">     * Execute an SQL SELECT query with replacement parameters.  The</a>
<span class="sourceLineNo">279</span><a id="line.279">     * caller is responsible for closing the connection.</a>
<span class="sourceLineNo">280</span><a id="line.280">     * @param &lt;T&gt; The type of object that the handler returns</a>
<span class="sourceLineNo">281</span><a id="line.281">     * @param conn The connection to execute the query in.</a>
<span class="sourceLineNo">282</span><a id="line.282">     * @param sql The query to execute.</a>
<span class="sourceLineNo">283</span><a id="line.283">     * @param rsh The handler that converts the results into an object.</a>
<span class="sourceLineNo">284</span><a id="line.284">     * @param params The replacement parameters.</a>
<span class="sourceLineNo">285</span><a id="line.285">     * @return A {@code Future} which returns the result of the query call.</a>
<span class="sourceLineNo">286</span><a id="line.286">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">287</span><a id="line.287">     */</a>
<span class="sourceLineNo">288</span><a id="line.288">    public &lt;T&gt; Future&lt;T&gt; query(final Connection conn, final String sql, final ResultSetHandler&lt;T&gt; rsh, final Object... params)</a>
<span class="sourceLineNo">289</span><a id="line.289">            throws SQLException {</a>
<span class="sourceLineNo">290</span><a id="line.290">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">291</span><a id="line.291"></a>
<span class="sourceLineNo">292</span><a id="line.292">            @Override</a>
<span class="sourceLineNo">293</span><a id="line.293">            public T call() throws Exception {</a>
<span class="sourceLineNo">294</span><a id="line.294">                return queryRunner.query(conn, sql, rsh, params);</a>
<span class="sourceLineNo">295</span><a id="line.295">            }</a>
<span class="sourceLineNo">296</span><a id="line.296"></a>
<span class="sourceLineNo">297</span><a id="line.297">        });</a>
<span class="sourceLineNo">298</span><a id="line.298">    }</a>
<span class="sourceLineNo">299</span><a id="line.299"></a>
<span class="sourceLineNo">300</span><a id="line.300">    /**</a>
<span class="sourceLineNo">301</span><a id="line.301">     * Execute an SQL SELECT query without any replacement parameters.  The</a>
<span class="sourceLineNo">302</span><a id="line.302">     * caller is responsible for closing the connection.</a>
<span class="sourceLineNo">303</span><a id="line.303">     * @param &lt;T&gt; The type of object that the handler returns</a>
<span class="sourceLineNo">304</span><a id="line.304">     * @param conn The connection to execute the query in.</a>
<span class="sourceLineNo">305</span><a id="line.305">     * @param sql The query to execute.</a>
<span class="sourceLineNo">306</span><a id="line.306">     * @param rsh The handler that converts the results into an object.</a>
<span class="sourceLineNo">307</span><a id="line.307">     * @return A {@code Future} which returns the result of the query call.</a>
<span class="sourceLineNo">308</span><a id="line.308">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">309</span><a id="line.309">     */</a>
<span class="sourceLineNo">310</span><a id="line.310">    public &lt;T&gt; Future&lt;T&gt; query(final Connection conn, final String sql, final ResultSetHandler&lt;T&gt; rsh) throws SQLException {</a>
<span class="sourceLineNo">311</span><a id="line.311">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">312</span><a id="line.312"></a>
<span class="sourceLineNo">313</span><a id="line.313">            @Override</a>
<span class="sourceLineNo">314</span><a id="line.314">            public T call() throws Exception {</a>
<span class="sourceLineNo">315</span><a id="line.315">                return queryRunner.query(conn, sql, rsh);</a>
<span class="sourceLineNo">316</span><a id="line.316">            }</a>
<span class="sourceLineNo">317</span><a id="line.317"></a>
<span class="sourceLineNo">318</span><a id="line.318">        });</a>
<span class="sourceLineNo">319</span><a id="line.319">    }</a>
<span class="sourceLineNo">320</span><a id="line.320"></a>
<span class="sourceLineNo">321</span><a id="line.321">    /**</a>
<span class="sourceLineNo">322</span><a id="line.322">     * Executes the given SELECT SQL query and returns a result object.</a>
<span class="sourceLineNo">323</span><a id="line.323">     * The {@code Connection} is retrieved from the</a>
<span class="sourceLineNo">324</span><a id="line.324">     * {@code DataSource} set in the constructor.</a>
<span class="sourceLineNo">325</span><a id="line.325">     * @param &lt;T&gt; The type of object that the handler returns</a>
<span class="sourceLineNo">326</span><a id="line.326">     * @param sql The SQL statement to execute.</a>
<span class="sourceLineNo">327</span><a id="line.327">     * @param rsh The handler used to create the result object from</a>
<span class="sourceLineNo">328</span><a id="line.328">     * the {@code ResultSet}.</a>
<span class="sourceLineNo">329</span><a id="line.329">     * @param params Initialize the PreparedStatement's IN parameters with</a>
<span class="sourceLineNo">330</span><a id="line.330">     * this array.</a>
<span class="sourceLineNo">331</span><a id="line.331">     * @return A {@code Future} which returns the result of the query call.</a>
<span class="sourceLineNo">332</span><a id="line.332">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">333</span><a id="line.333">     */</a>
<span class="sourceLineNo">334</span><a id="line.334">    public &lt;T&gt; Future&lt;T&gt; query(final String sql, final ResultSetHandler&lt;T&gt; rsh, final Object... params) throws SQLException {</a>
<span class="sourceLineNo">335</span><a id="line.335">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">336</span><a id="line.336"></a>
<span class="sourceLineNo">337</span><a id="line.337">            @Override</a>
<span class="sourceLineNo">338</span><a id="line.338">            public T call() throws Exception {</a>
<span class="sourceLineNo">339</span><a id="line.339">                return queryRunner.query(sql, rsh, params);</a>
<span class="sourceLineNo">340</span><a id="line.340">            }</a>
<span class="sourceLineNo">341</span><a id="line.341"></a>
<span class="sourceLineNo">342</span><a id="line.342">        });</a>
<span class="sourceLineNo">343</span><a id="line.343">    }</a>
<span class="sourceLineNo">344</span><a id="line.344"></a>
<span class="sourceLineNo">345</span><a id="line.345">    /**</a>
<span class="sourceLineNo">346</span><a id="line.346">     * Executes the given SELECT SQL without any replacement parameters.</a>
<span class="sourceLineNo">347</span><a id="line.347">     * The {@code Connection} is retrieved from the</a>
<span class="sourceLineNo">348</span><a id="line.348">     * {@code DataSource} set in the constructor.</a>
<span class="sourceLineNo">349</span><a id="line.349">     * @param &lt;T&gt; The type of object that the handler returns</a>
<span class="sourceLineNo">350</span><a id="line.350">     * @param sql The SQL statement to execute.</a>
<span class="sourceLineNo">351</span><a id="line.351">     * @param rsh The handler used to create the result object from</a>
<span class="sourceLineNo">352</span><a id="line.352">     * the {@code ResultSet}.</a>
<span class="sourceLineNo">353</span><a id="line.353">     *</a>
<span class="sourceLineNo">354</span><a id="line.354">     * @return A {@code Future} which returns the result of the query call.</a>
<span class="sourceLineNo">355</span><a id="line.355">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">356</span><a id="line.356">     */</a>
<span class="sourceLineNo">357</span><a id="line.357">    public &lt;T&gt; Future&lt;T&gt; query(final String sql, final ResultSetHandler&lt;T&gt; rsh) throws SQLException {</a>
<span class="sourceLineNo">358</span><a id="line.358">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">359</span><a id="line.359"></a>
<span class="sourceLineNo">360</span><a id="line.360">            @Override</a>
<span class="sourceLineNo">361</span><a id="line.361">            public T call() throws Exception {</a>
<span class="sourceLineNo">362</span><a id="line.362">                return queryRunner.query(sql, rsh);</a>
<span class="sourceLineNo">363</span><a id="line.363">            }</a>
<span class="sourceLineNo">364</span><a id="line.364"></a>
<span class="sourceLineNo">365</span><a id="line.365">        });</a>
<span class="sourceLineNo">366</span><a id="line.366">    }</a>
<span class="sourceLineNo">367</span><a id="line.367"></a>
<span class="sourceLineNo">368</span><a id="line.368">    /**</a>
<span class="sourceLineNo">369</span><a id="line.369">     * @deprecated No longer used by this class. Will be removed in a future version.</a>
<span class="sourceLineNo">370</span><a id="line.370">     * Class that encapsulates the continuation for update calls.</a>
<span class="sourceLineNo">371</span><a id="line.371">     */</a>
<span class="sourceLineNo">372</span><a id="line.372">    @Deprecated</a>
<span class="sourceLineNo">373</span><a id="line.373">    protected class UpdateCallableStatement implements Callable&lt;Integer&gt; {</a>
<span class="sourceLineNo">374</span><a id="line.374">        private final String sql;</a>
<span class="sourceLineNo">375</span><a id="line.375">        private final Object[] params;</a>
<span class="sourceLineNo">376</span><a id="line.376">        private final Connection conn;</a>
<span class="sourceLineNo">377</span><a id="line.377">        private final boolean closeConn;</a>
<span class="sourceLineNo">378</span><a id="line.378">        private final PreparedStatement ps;</a>
<span class="sourceLineNo">379</span><a id="line.379"></a>
<span class="sourceLineNo">380</span><a id="line.380">        /**</a>
<span class="sourceLineNo">381</span><a id="line.381">         *</a>
<span class="sourceLineNo">382</span><a id="line.382">         *</a>
<span class="sourceLineNo">383</span><a id="line.383">         * @param conn The connection to use for the batch call.</a>
<span class="sourceLineNo">384</span><a id="line.384">         * @param closeConn True if the connection should be closed, false otherwise.</a>
<span class="sourceLineNo">385</span><a id="line.385">         * @param ps The {@link PreparedStatement} to be executed.</a>
<span class="sourceLineNo">386</span><a id="line.386">         * @param sql The SQL statement to execute.</a>
<span class="sourceLineNo">387</span><a id="line.387">         * @param params An array of query replacement parameters.  Each row in</a>
<span class="sourceLineNo">388</span><a id="line.388">         *        this array is one set of batch replacement values.</a>
<span class="sourceLineNo">389</span><a id="line.389">         */</a>
<span class="sourceLineNo">390</span><a id="line.390">        public UpdateCallableStatement(final Connection conn, final boolean closeConn, final PreparedStatement ps, final String sql, final Object... params) {</a>
<span class="sourceLineNo">391</span><a id="line.391">            this.sql = sql;</a>
<span class="sourceLineNo">392</span><a id="line.392">            this.params = params;</a>
<span class="sourceLineNo">393</span><a id="line.393">            this.conn = conn;</a>
<span class="sourceLineNo">394</span><a id="line.394">            this.closeConn = closeConn;</a>
<span class="sourceLineNo">395</span><a id="line.395">            this.ps = ps;</a>
<span class="sourceLineNo">396</span><a id="line.396">        }</a>
<span class="sourceLineNo">397</span><a id="line.397"></a>
<span class="sourceLineNo">398</span><a id="line.398">        /**</a>
<span class="sourceLineNo">399</span><a id="line.399">         * The actual call to {@code executeUpdate()} method.</a>
<span class="sourceLineNo">400</span><a id="line.400">         *</a>
<span class="sourceLineNo">401</span><a id="line.401">         * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or</a>
<span class="sourceLineNo">402</span><a id="line.402">         *                (2) 0 for SQL statements that return nothing</a>
<span class="sourceLineNo">403</span><a id="line.403">         * @throws SQLException if a database access error occurs.</a>
<span class="sourceLineNo">404</span><a id="line.404">         * @see PreparedStatement#executeUpdate()</a>
<span class="sourceLineNo">405</span><a id="line.405">         */</a>
<span class="sourceLineNo">406</span><a id="line.406">        @Override</a>
<span class="sourceLineNo">407</span><a id="line.407">        public Integer call() throws SQLException {</a>
<span class="sourceLineNo">408</span><a id="line.408">            int rows = 0;</a>
<span class="sourceLineNo">409</span><a id="line.409"></a>
<span class="sourceLineNo">410</span><a id="line.410">            try {</a>
<span class="sourceLineNo">411</span><a id="line.411">                rows = ps.executeUpdate();</a>
<span class="sourceLineNo">412</span><a id="line.412">            } catch (final SQLException e) {</a>
<span class="sourceLineNo">413</span><a id="line.413">                rethrow(e, sql, params);</a>
<span class="sourceLineNo">414</span><a id="line.414">            } finally {</a>
<span class="sourceLineNo">415</span><a id="line.415">                close(ps);</a>
<span class="sourceLineNo">416</span><a id="line.416">                if (closeConn) {</a>
<span class="sourceLineNo">417</span><a id="line.417">                    close(conn);</a>
<span class="sourceLineNo">418</span><a id="line.418">                }</a>
<span class="sourceLineNo">419</span><a id="line.419">            }</a>
<span class="sourceLineNo">420</span><a id="line.420"></a>
<span class="sourceLineNo">421</span><a id="line.421">            return Integer.valueOf(rows);</a>
<span class="sourceLineNo">422</span><a id="line.422">        }</a>
<span class="sourceLineNo">423</span><a id="line.423"></a>
<span class="sourceLineNo">424</span><a id="line.424">    }</a>
<span class="sourceLineNo">425</span><a id="line.425"></a>
<span class="sourceLineNo">426</span><a id="line.426">    /**</a>
<span class="sourceLineNo">427</span><a id="line.427">     * Execute an SQL INSERT, UPDATE, or DELETE query without replacement</a>
<span class="sourceLineNo">428</span><a id="line.428">     * parameters.</a>
<span class="sourceLineNo">429</span><a id="line.429">     *</a>
<span class="sourceLineNo">430</span><a id="line.430">     * @param conn The connection to use to run the query.</a>
<span class="sourceLineNo">431</span><a id="line.431">     * @param sql The SQL to execute.</a>
<span class="sourceLineNo">432</span><a id="line.432">     * @return A {@code Future} which returns the number of rows updated.</a>
<span class="sourceLineNo">433</span><a id="line.433">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">434</span><a id="line.434">     */</a>
<span class="sourceLineNo">435</span><a id="line.435">    public Future&lt;Integer&gt; update(final Connection conn, final String sql) throws SQLException {</a>
<span class="sourceLineNo">436</span><a id="line.436">        return executorService.submit(new Callable&lt;Integer&gt;() {</a>
<span class="sourceLineNo">437</span><a id="line.437"></a>
<span class="sourceLineNo">438</span><a id="line.438">            @Override</a>
<span class="sourceLineNo">439</span><a id="line.439">            public Integer call() throws Exception {</a>
<span class="sourceLineNo">440</span><a id="line.440">                return Integer.valueOf(queryRunner.update(conn, sql));</a>
<span class="sourceLineNo">441</span><a id="line.441">            }</a>
<span class="sourceLineNo">442</span><a id="line.442"></a>
<span class="sourceLineNo">443</span><a id="line.443">        });</a>
<span class="sourceLineNo">444</span><a id="line.444">    }</a>
<span class="sourceLineNo">445</span><a id="line.445"></a>
<span class="sourceLineNo">446</span><a id="line.446">    /**</a>
<span class="sourceLineNo">447</span><a id="line.447">     * Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement</a>
<span class="sourceLineNo">448</span><a id="line.448">     * parameter.</a>
<span class="sourceLineNo">449</span><a id="line.449">     *</a>
<span class="sourceLineNo">450</span><a id="line.450">     * @param conn The connection to use to run the query.</a>
<span class="sourceLineNo">451</span><a id="line.451">     * @param sql The SQL to execute.</a>
<span class="sourceLineNo">452</span><a id="line.452">     * @param param The replacement parameter.</a>
<span class="sourceLineNo">453</span><a id="line.453">     * @return A {@code Future} which returns the number of rows updated.</a>
<span class="sourceLineNo">454</span><a id="line.454">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">455</span><a id="line.455">     */</a>
<span class="sourceLineNo">456</span><a id="line.456">    public Future&lt;Integer&gt; update(final Connection conn, final String sql, final Object param) throws SQLException {</a>
<span class="sourceLineNo">457</span><a id="line.457">        return executorService.submit(new Callable&lt;Integer&gt;() {</a>
<span class="sourceLineNo">458</span><a id="line.458"></a>
<span class="sourceLineNo">459</span><a id="line.459">            @Override</a>
<span class="sourceLineNo">460</span><a id="line.460">            public Integer call() throws Exception {</a>
<span class="sourceLineNo">461</span><a id="line.461">                return Integer.valueOf(queryRunner.update(conn, sql, param));</a>
<span class="sourceLineNo">462</span><a id="line.462">            }</a>
<span class="sourceLineNo">463</span><a id="line.463"></a>
<span class="sourceLineNo">464</span><a id="line.464">        });</a>
<span class="sourceLineNo">465</span><a id="line.465">    }</a>
<span class="sourceLineNo">466</span><a id="line.466"></a>
<span class="sourceLineNo">467</span><a id="line.467">    /**</a>
<span class="sourceLineNo">468</span><a id="line.468">     * Execute an SQL INSERT, UPDATE, or DELETE query.</a>
<span class="sourceLineNo">469</span><a id="line.469">     *</a>
<span class="sourceLineNo">470</span><a id="line.470">     * @param conn The connection to use to run the query.</a>
<span class="sourceLineNo">471</span><a id="line.471">     * @param sql The SQL to execute.</a>
<span class="sourceLineNo">472</span><a id="line.472">     * @param params The query replacement parameters.</a>
<span class="sourceLineNo">473</span><a id="line.473">     * @return A {@code Future} which returns the number of rows updated.</a>
<span class="sourceLineNo">474</span><a id="line.474">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">475</span><a id="line.475">     */</a>
<span class="sourceLineNo">476</span><a id="line.476">    public Future&lt;Integer&gt; update(final Connection conn, final String sql, final Object... params) throws SQLException {</a>
<span class="sourceLineNo">477</span><a id="line.477">        return executorService.submit(new Callable&lt;Integer&gt;() {</a>
<span class="sourceLineNo">478</span><a id="line.478"></a>
<span class="sourceLineNo">479</span><a id="line.479">            @Override</a>
<span class="sourceLineNo">480</span><a id="line.480">            public Integer call() throws Exception {</a>
<span class="sourceLineNo">481</span><a id="line.481">                return Integer.valueOf(queryRunner.update(conn, sql, params));</a>
<span class="sourceLineNo">482</span><a id="line.482">            }</a>
<span class="sourceLineNo">483</span><a id="line.483"></a>
<span class="sourceLineNo">484</span><a id="line.484">        });</a>
<span class="sourceLineNo">485</span><a id="line.485">    }</a>
<span class="sourceLineNo">486</span><a id="line.486"></a>
<span class="sourceLineNo">487</span><a id="line.487">    /**</a>
<span class="sourceLineNo">488</span><a id="line.488">     * Executes the given INSERT, UPDATE, or DELETE SQL statement without</a>
<span class="sourceLineNo">489</span><a id="line.489">     * any replacement parameters. The {@code Connection} is retrieved</a>
<span class="sourceLineNo">490</span><a id="line.490">     * from the {@code DataSource} set in the constructor.  This</a>
<span class="sourceLineNo">491</span><a id="line.491">     * {@code Connection} must be in auto-commit mode or the update will</a>
<span class="sourceLineNo">492</span><a id="line.492">     * not be saved.</a>
<span class="sourceLineNo">493</span><a id="line.493">     *</a>
<span class="sourceLineNo">494</span><a id="line.494">     * @param sql The SQL statement to execute.</a>
<span class="sourceLineNo">495</span><a id="line.495">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">496</span><a id="line.496">     * @return A {@code Future} which returns the number of rows updated.</a>
<span class="sourceLineNo">497</span><a id="line.497">     */</a>
<span class="sourceLineNo">498</span><a id="line.498">    public Future&lt;Integer&gt; update(final String sql) throws SQLException {</a>
<span class="sourceLineNo">499</span><a id="line.499">        return executorService.submit(new Callable&lt;Integer&gt;() {</a>
<span class="sourceLineNo">500</span><a id="line.500"></a>
<span class="sourceLineNo">501</span><a id="line.501">            @Override</a>
<span class="sourceLineNo">502</span><a id="line.502">            public Integer call() throws Exception {</a>
<span class="sourceLineNo">503</span><a id="line.503">                return Integer.valueOf(queryRunner.update(sql));</a>
<span class="sourceLineNo">504</span><a id="line.504">            }</a>
<span class="sourceLineNo">505</span><a id="line.505"></a>
<span class="sourceLineNo">506</span><a id="line.506">        });</a>
<span class="sourceLineNo">507</span><a id="line.507">    }</a>
<span class="sourceLineNo">508</span><a id="line.508"></a>
<span class="sourceLineNo">509</span><a id="line.509">    /**</a>
<span class="sourceLineNo">510</span><a id="line.510">     * Executes the given INSERT, UPDATE, or DELETE SQL statement with</a>
<span class="sourceLineNo">511</span><a id="line.511">     * a single replacement parameter.  The {@code Connection} is</a>
<span class="sourceLineNo">512</span><a id="line.512">     * retrieved from the {@code DataSource} set in the constructor.</a>
<span class="sourceLineNo">513</span><a id="line.513">     * This {@code Connection} must be in auto-commit mode or the</a>
<span class="sourceLineNo">514</span><a id="line.514">     * update will not be saved.</a>
<span class="sourceLineNo">515</span><a id="line.515">     *</a>
<span class="sourceLineNo">516</span><a id="line.516">     * @param sql The SQL statement to execute.</a>
<span class="sourceLineNo">517</span><a id="line.517">     * @param param The replacement parameter.</a>
<span class="sourceLineNo">518</span><a id="line.518">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">519</span><a id="line.519">     * @return A {@code Future} which returns the number of rows updated.</a>
<span class="sourceLineNo">520</span><a id="line.520">     */</a>
<span class="sourceLineNo">521</span><a id="line.521">    public Future&lt;Integer&gt; update(final String sql, final Object param) throws SQLException {</a>
<span class="sourceLineNo">522</span><a id="line.522">        return executorService.submit(new Callable&lt;Integer&gt;() {</a>
<span class="sourceLineNo">523</span><a id="line.523"></a>
<span class="sourceLineNo">524</span><a id="line.524">            @Override</a>
<span class="sourceLineNo">525</span><a id="line.525">            public Integer call() throws Exception {</a>
<span class="sourceLineNo">526</span><a id="line.526">                return Integer.valueOf(queryRunner.update(sql, param));</a>
<span class="sourceLineNo">527</span><a id="line.527">            }</a>
<span class="sourceLineNo">528</span><a id="line.528"></a>
<span class="sourceLineNo">529</span><a id="line.529">        });</a>
<span class="sourceLineNo">530</span><a id="line.530">    }</a>
<span class="sourceLineNo">531</span><a id="line.531"></a>
<span class="sourceLineNo">532</span><a id="line.532">    /**</a>
<span class="sourceLineNo">533</span><a id="line.533">     * Executes the given INSERT, UPDATE, or DELETE SQL statement.  The</a>
<span class="sourceLineNo">534</span><a id="line.534">     * {@code Connection} is retrieved from the {@code DataSource}</a>
<span class="sourceLineNo">535</span><a id="line.535">     * set in the constructor.  This {@code Connection} must be in</a>
<span class="sourceLineNo">536</span><a id="line.536">     * auto-commit mode or the update will not be saved.</a>
<span class="sourceLineNo">537</span><a id="line.537">     *</a>
<span class="sourceLineNo">538</span><a id="line.538">     * @param sql The SQL statement to execute.</a>
<span class="sourceLineNo">539</span><a id="line.539">     * @param params Initializes the PreparedStatement's IN (i.e. '?')</a>
<span class="sourceLineNo">540</span><a id="line.540">     * parameters.</a>
<span class="sourceLineNo">541</span><a id="line.541">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">542</span><a id="line.542">     * @return A {@code Future} which returns the number of rows updated.</a>
<span class="sourceLineNo">543</span><a id="line.543">     */</a>
<span class="sourceLineNo">544</span><a id="line.544">    public Future&lt;Integer&gt; update(final String sql, final Object... params) throws SQLException {</a>
<span class="sourceLineNo">545</span><a id="line.545">        return executorService.submit(new Callable&lt;Integer&gt;() {</a>
<span class="sourceLineNo">546</span><a id="line.546"></a>
<span class="sourceLineNo">547</span><a id="line.547">            @Override</a>
<span class="sourceLineNo">548</span><a id="line.548">            public Integer call() throws Exception {</a>
<span class="sourceLineNo">549</span><a id="line.549">                return Integer.valueOf(queryRunner.update(sql, params));</a>
<span class="sourceLineNo">550</span><a id="line.550">            }</a>
<span class="sourceLineNo">551</span><a id="line.551"></a>
<span class="sourceLineNo">552</span><a id="line.552">        });</a>
<span class="sourceLineNo">553</span><a id="line.553">    }</a>
<span class="sourceLineNo">554</span><a id="line.554"></a>
<span class="sourceLineNo">555</span><a id="line.555">    /**</a>
<span class="sourceLineNo">556</span><a id="line.556">     * Executes {@link QueryRunner#insert(String, ResultSetHandler)} asynchronously.</a>
<span class="sourceLineNo">557</span><a id="line.557">     *</a>
<span class="sourceLineNo">558</span><a id="line.558">     * @param &lt;T&gt; Return type expected</a>
<span class="sourceLineNo">559</span><a id="line.559">     * @param sql SQL insert statement to execute</a>
<span class="sourceLineNo">560</span><a id="line.560">     * @param rsh {@link ResultSetHandler} for handling the results</a>
<span class="sourceLineNo">561</span><a id="line.561">     * @return {@link Future} that executes a query runner insert</a>
<span class="sourceLineNo">562</span><a id="line.562">     * @see QueryRunner#insert(String, ResultSetHandler)</a>
<span class="sourceLineNo">563</span><a id="line.563">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">564</span><a id="line.564">     * @since 1.6</a>
<span class="sourceLineNo">565</span><a id="line.565">     */</a>
<span class="sourceLineNo">566</span><a id="line.566">    public &lt;T&gt; Future&lt;T&gt; insert(final String sql, final ResultSetHandler&lt;T&gt; rsh) throws SQLException {</a>
<span class="sourceLineNo">567</span><a id="line.567">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">568</span><a id="line.568"></a>
<span class="sourceLineNo">569</span><a id="line.569">            @Override</a>
<span class="sourceLineNo">570</span><a id="line.570">            public T call() throws Exception {</a>
<span class="sourceLineNo">571</span><a id="line.571">                return queryRunner.insert(sql, rsh);</a>
<span class="sourceLineNo">572</span><a id="line.572">            }</a>
<span class="sourceLineNo">573</span><a id="line.573"></a>
<span class="sourceLineNo">574</span><a id="line.574">        });</a>
<span class="sourceLineNo">575</span><a id="line.575">    }</a>
<span class="sourceLineNo">576</span><a id="line.576"></a>
<span class="sourceLineNo">577</span><a id="line.577">    /**</a>
<span class="sourceLineNo">578</span><a id="line.578">     * Executes {@link QueryRunner#insert(String, ResultSetHandler, Object...)} asynchronously.</a>
<span class="sourceLineNo">579</span><a id="line.579">     *</a>
<span class="sourceLineNo">580</span><a id="line.580">     * @param &lt;T&gt; Return type expected</a>
<span class="sourceLineNo">581</span><a id="line.581">     * @param sql SQL insert statement to execute</a>
<span class="sourceLineNo">582</span><a id="line.582">     * @param rsh {@link ResultSetHandler} for handling the results</a>
<span class="sourceLineNo">583</span><a id="line.583">     * @param params Parameter values for substitution in the SQL statement</a>
<span class="sourceLineNo">584</span><a id="line.584">     * @return {@link Future} that executes a query runner insert</a>
<span class="sourceLineNo">585</span><a id="line.585">     * @see QueryRunner#insert(String, ResultSetHandler, Object...)</a>
<span class="sourceLineNo">586</span><a id="line.586">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">587</span><a id="line.587">     * @since 1.6</a>
<span class="sourceLineNo">588</span><a id="line.588">     */</a>
<span class="sourceLineNo">589</span><a id="line.589">    public &lt;T&gt; Future&lt;T&gt; insert(final String sql, final ResultSetHandler&lt;T&gt; rsh, final Object... params) throws SQLException {</a>
<span class="sourceLineNo">590</span><a id="line.590">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">591</span><a id="line.591"></a>
<span class="sourceLineNo">592</span><a id="line.592">            @Override</a>
<span class="sourceLineNo">593</span><a id="line.593">            public T call() throws Exception {</a>
<span class="sourceLineNo">594</span><a id="line.594">                return queryRunner.insert(sql, rsh, params);</a>
<span class="sourceLineNo">595</span><a id="line.595">            }</a>
<span class="sourceLineNo">596</span><a id="line.596">        });</a>
<span class="sourceLineNo">597</span><a id="line.597">    }</a>
<span class="sourceLineNo">598</span><a id="line.598"></a>
<span class="sourceLineNo">599</span><a id="line.599">    /**</a>
<span class="sourceLineNo">600</span><a id="line.600">     * Executes {@link QueryRunner#insert(Connection, String, ResultSetHandler)} asynchronously.</a>
<span class="sourceLineNo">601</span><a id="line.601">     *</a>
<span class="sourceLineNo">602</span><a id="line.602">     * @param &lt;T&gt; Return type expected</a>
<span class="sourceLineNo">603</span><a id="line.603">     * @param conn {@link Connection} to use to execute the SQL statement</a>
<span class="sourceLineNo">604</span><a id="line.604">     * @param sql SQL insert statement to execute</a>
<span class="sourceLineNo">605</span><a id="line.605">     * @param rsh {@link ResultSetHandler} for handling the results</a>
<span class="sourceLineNo">606</span><a id="line.606">     * @return {@link Future} that executes a query runner insert</a>
<span class="sourceLineNo">607</span><a id="line.607">     * @see QueryRunner#insert(Connection, String, ResultSetHandler)</a>
<span class="sourceLineNo">608</span><a id="line.608">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">609</span><a id="line.609">     * @since 1.6</a>
<span class="sourceLineNo">610</span><a id="line.610">     */</a>
<span class="sourceLineNo">611</span><a id="line.611">    public &lt;T&gt; Future&lt;T&gt; insert(final Connection conn, final String sql, final ResultSetHandler&lt;T&gt; rsh) throws SQLException {</a>
<span class="sourceLineNo">612</span><a id="line.612">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">613</span><a id="line.613"></a>
<span class="sourceLineNo">614</span><a id="line.614">            @Override</a>
<span class="sourceLineNo">615</span><a id="line.615">            public T call() throws Exception {</a>
<span class="sourceLineNo">616</span><a id="line.616">                return queryRunner.insert(conn, sql, rsh);</a>
<span class="sourceLineNo">617</span><a id="line.617">            }</a>
<span class="sourceLineNo">618</span><a id="line.618">        });</a>
<span class="sourceLineNo">619</span><a id="line.619">    }</a>
<span class="sourceLineNo">620</span><a id="line.620"></a>
<span class="sourceLineNo">621</span><a id="line.621">    /**</a>
<span class="sourceLineNo">622</span><a id="line.622">     * Executes {@link QueryRunner#insert(Connection, String, ResultSetHandler, Object...)} asynchronously.</a>
<span class="sourceLineNo">623</span><a id="line.623">     *</a>
<span class="sourceLineNo">624</span><a id="line.624">     * @param &lt;T&gt; Return type expected</a>
<span class="sourceLineNo">625</span><a id="line.625">     * @param conn {@link Connection} to use to execute the SQL statement</a>
<span class="sourceLineNo">626</span><a id="line.626">     * @param sql SQL insert statement to execute</a>
<span class="sourceLineNo">627</span><a id="line.627">     * @param rsh {@link ResultSetHandler} for handling the results</a>
<span class="sourceLineNo">628</span><a id="line.628">     * @param params Parameter values for substitution in the SQL statement</a>
<span class="sourceLineNo">629</span><a id="line.629">     * @return {@link Future} that executes a query runner insert</a>
<span class="sourceLineNo">630</span><a id="line.630">     * @see QueryRunner#insert(Connection, String, ResultSetHandler, Object...)</a>
<span class="sourceLineNo">631</span><a id="line.631">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">632</span><a id="line.632">     * @since 1.6</a>
<span class="sourceLineNo">633</span><a id="line.633">     */</a>
<span class="sourceLineNo">634</span><a id="line.634">    public &lt;T&gt; Future&lt;T&gt; insert(final Connection conn, final String sql, final ResultSetHandler&lt;T&gt; rsh, final Object... params) throws SQLException {</a>
<span class="sourceLineNo">635</span><a id="line.635">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">636</span><a id="line.636"></a>
<span class="sourceLineNo">637</span><a id="line.637">            @Override</a>
<span class="sourceLineNo">638</span><a id="line.638">            public T call() throws Exception {</a>
<span class="sourceLineNo">639</span><a id="line.639">                return queryRunner.insert(conn, sql, rsh, params);</a>
<span class="sourceLineNo">640</span><a id="line.640">            }</a>
<span class="sourceLineNo">641</span><a id="line.641">        });</a>
<span class="sourceLineNo">642</span><a id="line.642">    }</a>
<span class="sourceLineNo">643</span><a id="line.643"></a>
<span class="sourceLineNo">644</span><a id="line.644">    /**</a>
<span class="sourceLineNo">645</span><a id="line.645">     * {@link QueryRunner#insertBatch(String, ResultSetHandler, Object[][])} asynchronously.</a>
<span class="sourceLineNo">646</span><a id="line.646">     *</a>
<span class="sourceLineNo">647</span><a id="line.647">     * @param &lt;T&gt; Return type expected</a>
<span class="sourceLineNo">648</span><a id="line.648">     * @param sql SQL insert statement to execute</a>
<span class="sourceLineNo">649</span><a id="line.649">     * @param rsh {@link ResultSetHandler} for handling the results</a>
<span class="sourceLineNo">650</span><a id="line.650">     * @param params An array of query replacement parameters.  Each row in</a>
<span class="sourceLineNo">651</span><a id="line.651">     *        this array is one set of batch replacement values.</a>
<span class="sourceLineNo">652</span><a id="line.652">     * @return {@link Future} that executes a query runner batch insert</a>
<span class="sourceLineNo">653</span><a id="line.653">     * @see QueryRunner#insertBatch(String, ResultSetHandler, Object[][])</a>
<span class="sourceLineNo">654</span><a id="line.654">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">655</span><a id="line.655">     * @since 1.6</a>
<span class="sourceLineNo">656</span><a id="line.656">     */</a>
<span class="sourceLineNo">657</span><a id="line.657">    public &lt;T&gt; Future&lt;T&gt; insertBatch(final String sql, final ResultSetHandler&lt;T&gt; rsh, final Object[][] params) throws SQLException {</a>
<span class="sourceLineNo">658</span><a id="line.658">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">659</span><a id="line.659"></a>
<span class="sourceLineNo">660</span><a id="line.660">            @Override</a>
<span class="sourceLineNo">661</span><a id="line.661">            public T call() throws Exception {</a>
<span class="sourceLineNo">662</span><a id="line.662">                return queryRunner.insertBatch(sql, rsh, params);</a>
<span class="sourceLineNo">663</span><a id="line.663">            }</a>
<span class="sourceLineNo">664</span><a id="line.664">        });</a>
<span class="sourceLineNo">665</span><a id="line.665">    }</a>
<span class="sourceLineNo">666</span><a id="line.666"></a>
<span class="sourceLineNo">667</span><a id="line.667">    /**</a>
<span class="sourceLineNo">668</span><a id="line.668">     * {@link QueryRunner#insertBatch(Connection, String, ResultSetHandler, Object[][])} asynchronously.</a>
<span class="sourceLineNo">669</span><a id="line.669">     *</a>
<span class="sourceLineNo">670</span><a id="line.670">     * @param &lt;T&gt; Return type expected</a>
<span class="sourceLineNo">671</span><a id="line.671">     * @param conn {@link Connection} to use to execute the SQL statement</a>
<span class="sourceLineNo">672</span><a id="line.672">     * @param sql SQL insert statement to execute</a>
<span class="sourceLineNo">673</span><a id="line.673">     * @param rsh {@link ResultSetHandler} for handling the results</a>
<span class="sourceLineNo">674</span><a id="line.674">     * @param params An array of query replacement parameters.  Each row in</a>
<span class="sourceLineNo">675</span><a id="line.675">     *        this array is one set of batch replacement values.</a>
<span class="sourceLineNo">676</span><a id="line.676">     * @return {@link Future} that executes a query runner batch insert</a>
<span class="sourceLineNo">677</span><a id="line.677">     * @see QueryRunner#insertBatch(Connection, String, ResultSetHandler, Object[][])</a>
<span class="sourceLineNo">678</span><a id="line.678">     * @throws SQLException if a database access error occurs</a>
<span class="sourceLineNo">679</span><a id="line.679">     * @since 1.6</a>
<span class="sourceLineNo">680</span><a id="line.680">     */</a>
<span class="sourceLineNo">681</span><a id="line.681">    public &lt;T&gt; Future&lt;T&gt; insertBatch(final Connection conn, final String sql, final ResultSetHandler&lt;T&gt; rsh, final Object[][] params) throws SQLException {</a>
<span class="sourceLineNo">682</span><a id="line.682">        return executorService.submit(new Callable&lt;T&gt;() {</a>
<span class="sourceLineNo">683</span><a id="line.683"></a>
<span class="sourceLineNo">684</span><a id="line.684">            @Override</a>
<span class="sourceLineNo">685</span><a id="line.685">            public T call() throws Exception {</a>
<span class="sourceLineNo">686</span><a id="line.686">                return queryRunner.insertBatch(conn, sql, rsh, params);</a>
<span class="sourceLineNo">687</span><a id="line.687">            }</a>
<span class="sourceLineNo">688</span><a id="line.688">        });</a>
<span class="sourceLineNo">689</span><a id="line.689">    }</a>
<span class="sourceLineNo">690</span><a id="line.690"></a>
<span class="sourceLineNo">691</span><a id="line.691">}</a>




























































</pre>
</div>
</main>
</body>
</html>
